const util = require('../../../utils/util.js');
const api = require('../../../config/api.js');
const user = require('../../../utils/user.js');

//index.js
//获取应用实例
const app = getApp()

// pages/ucenter/list/list.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    has1: false,
    alloder: '',
    goods: {},
    id: '',
    TabCur: 0,
    scrollLeft: 0,
    list: [{
        name: '全部订单'
      },
      {
        name: '待付款'
      },
      {
        name: '待发货'
      },
      {
        name: '已完成'
      }

    ],
    allorder: [
    ],
    waitorder: [],
    getorder: [],
    overorder: []
  },
  tabSelect(e) {
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id - 1) * 60
    })
    wx.setStorageSync('status', this.data.TabCur);
    this.getwait()
  },





  // 全部订单
  getall() {
  
          this.setData({
            allorder: app.globalData.allorder,
          })       
  },
  // 状态订单
  getwait() {
    let that = this
    util.request(api.QueryOrderStatus + (that.data.TabCur - 1), {

    }, 'post', {
      'Content-Type': 'application/json;charset=UTF-8',
      'X-Qxmall-Token': wx.getStorageSync('token')
    }).then(function(res) {
      console.log(res)
      if (res.code == 200) {
        if (res.data.orderList.length == 0) {
          that.setData({
            has1: true,
            waitorder: []
          })
        } else {
          that.setData({
            has1: false,
            waitorder: res.data.orderList,
            id: res.data.orderList[0].commodityId
          })
          
        }
      }
    });
  },


  goorder(e) {
    console.log(e)
    wx.navigateTo({
      url: '../listorder/listorder?orderSn=' + e.currentTarget.dataset.id,
    })
  },
  goorder1(e) {
    console.log(e.currentTarget.dataset.id)
    wx.navigateTo({
      url: '../listorder/listorder?orderSn=' + e.currentTarget.dataset.id,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getall()
    console.log(options.id)
    this.setData({
      TabCur: options.id
    })
    this.getwait()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
   
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})